﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Newtonsoft.Json;

namespace Demo
{
    /// <summary>
    /// Handler1 的摘要说明
    /// </summary>
    public class Handler1 : IHttpHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            DateTime dateTimeMin = Convert.ToDateTime("2007-1-1");//DateTime.Parse("2007-1-1")
            List<UserInfo> lstUserInfo = new List<UserInfo>();
            for (int i = 0; i < 5; i++)
            {
                UserInfo user = new UserInfo();
                user.Name = "张" + i.ToString();
                //取随机的日期
                Random rnd = new Random();
                int n = rnd.Next(365);
                DateTime dateTime = dateTimeMin.AddDays(n);
                user.Birthday = dateTime;
                lstUserInfo.Add(user);
            } 
           //完成用户信息和图表要求的数据格式一一对应
            List<GraphData> lstGraphData = new List<GraphData>();
            for (int i = 0; i < lstUserInfo .Count ; i++)
            {
                GraphData graphData = new GraphData();
                graphData.name = lstUserInfo[i].Name;
                graphData.value = "11";
                lstGraphData.Add(graphData);
            }
            string json = JsonConvert.SerializeObject(lstGraphData);
            context.Response.Write(json);
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }
    }
}